package org.skipper.samples.redission.pubsub;

import org.redisson.api.RedissonClient;
import org.skipper.samples.redission.enums.RedisKeyEnum;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author shoujian
 * Date: 2021-08-27
 * Time: 下午5:54
 */
@Component
public class PubSubSource {

    @Qualifier(value = "redis-cloud_0")
    @Resource
    private RedissonClient redissonClient;

    public void psubscribe() {
        //todo 待完善
//        redissonClient.getPatternTopic(RedisKeyEnum.PUB_SUB_TEST.getCode()).addListener()
    }

    public void publish() {
        redissonClient.getTopic(RedisKeyEnum.PUB_SUB_TEST.getCode()).publish(1);
    }

    public void rpop() {
        redissonClient.getDeque(RedisKeyEnum.PUB_SUB_TEST.getCode()).pollLast();
        redissonClient.getDeque(RedisKeyEnum.PUB_SUB_TEST.getCode()).removeLast();
    }

    public void rpoplpush() {
        redissonClient.getDeque(RedisKeyEnum.PUB_SUB_TEST.getCode()).pollLastAndOfferFirstTo("test");
    }

    public void rpush() {
        redissonClient.getList(RedisKeyEnum.PUB_SUB_TEST.getCode()).add(1);
    }

    public void subscribe() {
//        redissonClient.getTopic(RedisKeyEnum.PUB_SUB_TEST.getCode()).addListener();
    }

    public void unsubscribe() {
//        redissonClient.getTopic(RedisKeyEnum.PUB_SUB_TEST.getCode()).removeListener();
    }

}
